<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个人中心-维多购物平台</title>
    <link rel="shortcut icon" href="./images/favicon.ico" type="image/x-icon" />
    <link href="./bootstrap-3.4.1/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="./css/style.css">
    <script src="./js/jquery-3.4.1.min.js"></script>
    <script src="./bootstrap-3.4.1/js/bootstrap.min.js"></script>
    <script src="./js/index.js" type="module" defer="defer"></script>
    <script src="./js/cookie.js"></script>
    <style>
        header {
            background-color: rgba(0,0,0,.7);;
            backdrop-filter: blur(20px);
        }

        main {
            padding: 10px;
        }

        .account-center {
            width: 100%;
            margin: 60px 0 50px 0;
            max-width: 1200px;
        }

        .account-center-content {
            display: flex;
            align-items: center;
            background-color: var(--color-background);
            border-radius: 3px;
        }

        .img-head {
            width: 140px;
            height: 140px;
            background-image: url("./images/user/head.gif");
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
            border-radius: 50%;
            margin: 20px;
        }

        .account-info {
            width: calc(-200px + 100%);
            display: flex;
            justify-content: space-between;
        }

        .portal-sub {
            width: 100%;
            background-color: var(--color-background);
            border-radius: 3px;
            padding: 20px;
            margin: 30px 0 0 0;
        }

        .info-list {
            width: 100%;
            display: flex;
            justify-content: space-between;
            margin: 0;
            column-gap: 10px;
        }

        .info-list li {
            display: flex;
            align-items: center;
            column-gap: 10px;
        }

        .user-account-details {
            display: flex;
            row-gap: 5px;
            flex-direction: column;
            align-items: flex-start;
        }

        h2 {
            font-size: 25px;
            font-weight: 600;
            margin-bottom: 20px;
        }

        h4 {
            font-size: 16px;
            font-weight: 600;
        }

        .account-center .uid {
            font-size: 12px;
            color: var(--ui-colors-neutral9);
        }

        .account-center p {
            width: 100px;
            height: 30px;
            margin: 0;
            border-radius: 3px;
            align-items: center;
            justify-content: center;
            border: 2px solid #ff5c00b0;
            background-color: #ff5c0085;
            display: flex;
            column-gap: 3px;
            cursor: pointer;
            color: #fff;
            fill: #fff;
        }

        .account-center p:hover {
            background-color: #ff5c00b0;
        }

        .account-center a {
            color: var(--ui-colors-neutral9);
            fill: var(--ui-colors-neutral9);
            display: flex;
            column-gap: 3px;
            cursor: pointer;
        }

        .account-center a:hover {
            color: var(--ui-colors-orange);
            fill: var(--ui-colors-orange);
        } 

        
        .modal-body {
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
        }

        .modal-content {
            background-color: var(--color-background-soft);
            padding: 0 10px 10px 10px;
        }

        .modal-content .title {
            display: flex;
            justify-content: space-between;
            align-items: center;
            border-bottom: 2px solid var(--ui-colors-neutral5);
        }

        .modal-btn-close {
            background-color: var(--color-none);
            border: none;
            font-size: 30px;
        }

        .modal-content form {
            display: flex;
            flex-direction: column;
            row-gap: 10px;
            margin: 10px 0;
        }

        .modal-content form .form-line {
            display: flex;
            align-items: center;
        }

        .modal-content form span {
            font-size: 12px;
            font-weight: 600;
        }

        .modal-content form input {
            width: 450px;
            font-size: 14px;
            line-height: 1.5rem;
            min-height: 40px;
            border-radius: 5px;
            padding-inline-start: 10px;
            padding-inline-end: 10px;
            border: 2px solid var(--color-none);
            background-color: var(--ui-colors-neutral3);
            color: var(--color-text);
        }

        .modal-content form input:hover {
            background-color: var(--ui-colors-neutral4);
        }

        .modal-content form input:focus {
            outline: none;
            border: 2px solid var(--ui-colors-orange);
        }

        .modal-content .operate {
            display: flex;
            justify-content: flex-end;
            column-gap: 10px;
        }

        .modal-content .operate .btn-primary {
            background-color: var(--ui-colors-orange);
        }

        .modal-content button:focus {
            display: none;
        }
    </style>
</head>

<body>
    <header id="header" class="has-user">
        <div class="logo">
            <img src="./images/logo.png" alt="logo">
        </div>
        <nav class="main-menu">
            <a href="/">首页</a>
            <a href="/allphone">手机</a>
            <a href="/allcomputer">电脑</a>
        </nav>
        <div class="user-info">
            <div class="user-operate">
                <div class="user-one">
                    <div class="user-name">
                        <span id="username">用户名</span>
                        <svg t="1687403727017" class="icon-user" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="872" width="15" height="15"><path d="M468.7872 738.5088c0-10.4448 4.096-20.8896 12.0832-28.8768L929.792 260.7104c15.9744-15.9744 41.984-15.9744 57.9584 0 7.9872 7.9872 12.0832 18.432 12.0832 28.8768s-4.096 20.8896-12.0832 28.8768L538.624 767.3856c-15.9744 15.9744-41.984 15.9744-57.9584 0-7.9872-7.9872-11.8784-18.432-11.8784-28.8768z" p-id="873"></path><path d="M30.3104 260.9152c7.9872-7.9872 18.432-12.0832 28.8768-12.0832s20.8896 4.096 28.8768 12.0832l448.9216 448.9216c15.9744 15.9744 15.9744 41.984 0 57.9584-7.9872 7.9872-18.432 12.0832-28.8768 12.0832s-20.8896-4.096-29.0816-12.0832L30.3104 318.6688c-15.9744-15.9744-15.9744-41.7792 0-57.7536z" p-id="874"></path></svg>
                    </div>
                    <div class="user-links">
                        <ul>
                            <li><a href="/user"  target="_blank">个人中心</a></li>
                            <li><a href="/wallet"  target="_blank">我的钱包</a></li>
                            <li><a href="/order"  target="_blank">我的订单</a></li>
                            <li><a href="/uevaluate"  target="_blank">评论晒单</a></li>
                            <li><a href="/" onclick="ClearCookie()">退出登录</a></li>
                        </ul>
                    </div>
                </div>
            </div>
            <a href="/trolley" class="mini-shopping-cart">购物车(<span id="count-trolley">0</span>)</a>
        </div>
    </header>
    <main class="user">
        <div class="account-center">
            <div class="account-center-header">
                <h2>个人中心</h2>
            </div>
            <div class="account-center-content">
                <div class="img-head"></div>
                <div class="account-info">
                    <div class="user-account-details">
                        <h4 id="uname"></h4>
                        <div class="uid">UID: <span id="uid"></span></div>
                        <div class="telephone">绑定手机号: <span id="phone"></span></div>
                        <div class="address">地址: <span id="address"></span></div>
                    </div>
                    <p data-toggle="modal" data-target="#updateUserInfo">
                        编辑信息
                    </p>
                </div>
            </div>
            <div class="portal-sub">
                <ul class="info-list">
                    <li>
                        <img src="./images/user/portal-icon-1.png" alt="">
                        <div>
                            <h4>
                                待支付的订单：<span class="num" id="unpaid_order"></span>
                            </h4>
                            <a href="/order#list-nopay">
                                查看待支付订单
                                <svg t="1687353674344" class="icon-more" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5801" width="30" height="30"><path d="M512 64C264.8 64 64 264.8 64 512s200.8 448 448 448 448-200.8 448-448S759.2 64 512 64zM398.4 784l-45.6-45.6L580 512 353.6 285.6l45.6-45.6 272 272-272.8 272z" p-id="5802"></path></svg>

                            </a>
                        </div>
                    </li>
                    <li >
                        <img src="./images/user/portal-icon-2.png" alt="">
                        <div>
                            <h4>
                                待收货的订单：<span class="num" id="pending_order"></span>
                            </h4>
                            <a href="/order#list-noreceive">
                                查看待收货订单
                                <svg t="1687353674344" class="icon-more" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5801" width="30" height="30"><path d="M512 64C264.8 64 64 264.8 64 512s200.8 448 448 448 448-200.8 448-448S759.2 64 512 64zM398.4 784l-45.6-45.6L580 512 353.6 285.6l45.6-45.6 272 272-272.8 272z" p-id="5802"></path></svg>

                            </a>
                        </div>
                    </li>
                    <li>
                        <img src="./images/user/portal-icon-3.png" alt="">
                        <div>
                            <h4>
                                待评价商品数：<span class="num" id="review_order"></span>
                            </h4>
                            <a href="/order#list-noevaluate">
                                查看待评价商品
                                <svg t="1687353674344" class="icon-more" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5801" width="30" height="30"><path d="M512 64C264.8 64 64 264.8 64 512s200.8 448 448 448 448-200.8 448-448S759.2 64 512 64zM398.4 784l-45.6-45.6L580 512 353.6 285.6l45.6-45.6 272 272-272.8 272z" p-id="5802"></path></svg>

                            </a>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </main>
    <div class="bottom">
        <div class="footer-links clearfix">
            <dl class="col-links col-links-first">
                <dt></dt>
            </dl>
            <dl class="col-links ">
                <dt>选购指南</dt>
                <dd><a rel="nofollow" href="/allphone">手机</a></dd>
                <dd><a rel="nofollow" href="/allcomputer">电脑</a></dd>
            </dl>

            <dl class="col-links ">
                <dt>服务中心</dt>
                <dd><a rel="nofollow" onclick="openChat()" style="cursor: pointer">智能客服</a></dd>
                <dd><a rel="nofollow" href="/order" target="_blank">订单查询</a></dd>
            </dl>

            <dl class="col-links ">
                <dt>关于</dt>
                <dd><a rel="nofollow" href="https://sugarscat.com" target="_blank">了解我们</a></dd>
            </dl>
        </div>
        <div class="site-info">
            <div class="logo ir"></div>
            <div class="info-text">
                <p class="sites">
                    <a rel="nofollow" href="/" target="_blank">维多购物平台</a>
                    <span class="sep">|</span>
                    <a rel="nofollow" href="/privacy" target="_blank"
                    >隐私政策</a
                    >
                </p>
                <p class="sites">
                    <a rel="nofollow" href="http://www.cca.org.cn/" target="_blank"
                    >中国消费者协会</a
                    >
                    <span class="sep">|</span>
                    <a rel="nofollow" href="http://www.bj315.org/" target="_blank"
                    >北京市消费者协会</a
                    >
                </p>
                <p>
                    &copy;2023-至今 版权所有 维多购物平台
                    <br />
                    本网站所列数据、图片，均来自互联网已公开信息，仅供交流学习！
                </p>
            </div>
        </div>
    </div>
    <!-- 更新用户信息弹窗 -->
    <div class="modal fade" id="updateUserInfo" tabindex="-1" role="dialog"   aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-body">
            <div class="modal-content">
                <div class="title">
                    <h4 id="myModalLabel">编辑信息</h4>
                    <button class="modal-btn-close" type="button" data-dismiss="modal"   aria-hidden="true">&times;</button>
                </div>
                <div class="content">
                    <form role="form">
                        <span>用户名：</span>
                        <input type="text" name="" id="update-name" placeholder="请输入用户名" required>
                        <span>手机号码：</span>
                        <input type="text" name="" id="update-phone" placeholder="请输入手机号码" required>
                        <span>地址：</span>
                        <input type="text" name="" id="update-address" placeholder="请输入地址">
                    </form>
                </div>
                <div class="operate">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary"   onclick="updateInfo()">更新</button>
                </div>
            </div><!--   /.modal-content -->
        </div><!-- /.modal -->
    </div>
</body>
<script src="./js/message.js"></script>
<script src="./js/chat.js"></script>
<script>
    let id = GetCookie("id")
    let token = GetCookie("token")
    if (token.length>0) {
        $.ajax({
            url:"/api/user",
            method:"post",
            data:{
                id: id,
                token: token
            },
            success(res){
                if(res.code===1001) {
                    document.getElementById("username").innerText = res.user
                    document.getElementById("uname").innerText = res.user
                    document.getElementById("uid").innerText = res.uid
                    document.getElementById("phone").innerText = res.tel
                    document.getElementById("address").innerText = res.address
                    
                    document.getElementById("unpaid_order").innerText = res.unpaid_order
                    document.getElementById("pending_order").innerText = res.pending_order
                    document.getElementById("review_order").innerText = res.review_order

                    document.getElementById("update-name").value = res.user
                    document.getElementById("update-phone").value = res.tel
                    document.getElementById("update-address").value = res.address
                    
                } else {
                    AddMessage("warning", "用户令牌过期")
                    setTimeout(()=>{
                        location.href = "/account#login"
                    }, 500)
                }
            }
        })
    } else {
        AddMessage("error", "未登录")
        setTimeout(()=>{
            location.href = "/account#login"
        }, 500)
    }

    function updateInfo() {
        let id = GetCookie("id")
        let token = GetCookie("token")
        if (token.length>0) {
            let namereg=/^[\u4e00-\u9fa5]{0,}$/;
            let telreg=/(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
            // 此处验证可通过正则匹配
            if (namereg.test(document.getElementById("update-name").value)) {
                if (telreg.test(document.getElementById("update-phone").value)) {
                    $.ajax({
                        url:"/api/userupdate",
                        method:"post",
                        data:{
                            id: id,
                            token: token,
                            username: document.getElementById("update-name").value,
                            tel: document.getElementById("update-phone").value,
                            address: document.getElementById("update-address").value
                        },
                        success(res){
                            if(res.code===1001) {
                                AddMessage("success", "更新成功")
                                setTimeout(()=>{
                                    location.reload()
                                }, 500)
                            } else {
                                AddMessage("warning", "用户令牌过期")
                                setTimeout(()=>{
                                    location.href = "/account#login"
                                }, 500)
                            }
                        }
                    })
                } else {
                    AddMessage("warning", "手机号码格式不合法")
                }
            } else {
                AddMessage("warning", "用户名只可是中文")
            }
        } else {
            AddMessage("error", "未登录")
            setTimeout(()=>{
                location.href = "/account#login"
            }, 500)
        }
    }
</script>
</html>